package com.youlai.boot.system.controller;

import com.youlai.boot.common.model.Option;
import com.youlai.boot.system.service.TomYzTableService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.youlai.boot.system.model.form.TomYzTableForm;
import com.youlai.boot.system.model.query.TomYzTableQuery;
import com.youlai.boot.system.model.vo.TomYzTableVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.boot.common.result.PageResult;
import com.youlai.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

import java.util.List;

/**
 * 驿站管理前端控制层
 *
 * @author youlaitech
 * @since 2025-09-16 22:35
 */
@Tag(name = "驿站管理接口")
@RestController
@RequestMapping("/api/v1/tomYzTables")
@RequiredArgsConstructor
public class TomYzTableController  {

    private final TomYzTableService tomYzTableService;

    @Operation(summary = "驿站管理分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('system:tomYzTable:query')")
    public PageResult<TomYzTableVO> getTomYzTablePage(TomYzTableQuery queryParams ) {
        IPage<TomYzTableVO> result = tomYzTableService.getTomYzTablePage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增驿站管理")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('system:tomYzTable:add')")
    public Result<Void> saveTomYzTable(@RequestBody @Valid TomYzTableForm formData ) {
        boolean result = tomYzTableService.saveTomYzTable(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取驿站管理表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('system:tomYzTable:edit')")
    public Result<TomYzTableForm> getTomYzTableForm(
        @Parameter(description = "驿站管理ID") @PathVariable Long id
    ) {
        TomYzTableForm formData = tomYzTableService.getTomYzTableFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改驿站管理")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('system:tomYzTable:edit')")
    public Result<Void> updateTomYzTable(
            @Parameter(description = "驿站管理ID") @PathVariable Long id,
            @RequestBody @Validated TomYzTableForm formData
    ) {
        boolean result = tomYzTableService.updateTomYzTable(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除驿站管理")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('system:tomYzTable:delete')")
    public Result<Void> deleteTomYzTables(
        @Parameter(description = "驿站管理ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = tomYzTableService.deleteTomYzTables(ids);
        return Result.judge(result);
    }

    @Operation(summary = "驿站下拉列表")
    @GetMapping("/options")
    public Result<List<Option<Long>>> getOptions() {
        List<Option<Long>> list = tomYzTableService.getOptions();
        return Result.success(list);
    }
}
